const path = require("path");
const webpack = require("webpack");
const ExtractTextPlugin = require('extract-text-webpack-plugin');


module.exports = {
    entry: {
        app: ['babel-polyfill', "./src/apps/index.js"],
        bind: ['babel-polyfill', "./src/apps/index-bind.js"],
        callback: ['babel-polyfill', "./src/apps/index-callback.js"]
    },
    output: {
        path: "./server/dist",
        filename: "bundle-[name]-[chunkhash].js",
        chunkFilename: "[id]-chunk-[chunkhash].js"
    },
    externals: {
        jquery: 'window.$',
        $: 'window.$',
        'babel-polyfill': 'window._babelPolyfill',
        'QMRoute': 'window.QMRoute'

    },
    resolve: {
        modulesDirectories: ['', 'node_modules', path.resolve(__dirname, './src/web_modules')],
        extensions: ['', '.web.js', '.js', '.json']
    },
    module: {
        loaders: [
            {test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader?cacheDirectory'},
            {test: /\.json$/, loader: 'json-loader'},
            {test: /\.less$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader!less-loader')},
            {test: /\.css$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader')},
            {test: /\.(png|gif)$/, loader: 'file-loader'}
        ]
    },
    plugins: [
        new webpack.BannerPlugin('This file is created by qm'),
        new ExtractTextPlugin('[name].css', {
            disable: false,
            allChunks: true
        }),
        new webpack.DefinePlugin({
            __DEBUG__: false,
            __DEV__: false,
            'process.env': {
                NODE_ENV: JSON.stringify('production')
            }
        }),
        new webpack.optimize.CommonsChunkPlugin({
            // names: ['app','bind'],
            name: ['app', 'bind'],
            minChunks: Infinity,
            async: true,
            children: true
        }),
        new webpack.DllReferencePlugin({
            context: __dirname,
            manifest: require('./dll/vendor-manifest.json')
        }),
        new webpack.optimize.UglifyJsPlugin({
            compress: {warnings: false}
        }),
        new webpack.optimize.DedupePlugin()
    ]
};